﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace unTroublemakerUI
{
    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            
        }

        private void ScrollTree(object sender, MouseWheelEventArgs e)
        {
            var scrollViewer = FindChild<ScrollViewer>((DependencyObject)sender);
            scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - e.Delta);
            e.Handled = true;
        }

        private T FindChild<T>(DependencyObject sender) where T : class
        {
            var cast = sender as T;
            if (cast != null)
                return cast;

            int children = VisualTreeHelper.GetChildrenCount(sender);
            for (int i = 0; i < children; ++i)
            {
                var child = FindChild<T>(VisualTreeHelper.GetChild(sender, i));
                if (child != null)
                    return child;
            }

            return null;
        }
    }
}
